<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <html>
      <head>
        <style type="text/css">
          .pass
          {
          background-color: #AAFFAA; /* light green */
          filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#FFFFFF', EndColorStr='#AAFFAA')
          }

          .fail {
          background-color: #FFAAAA; /* light red */
          filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#FFFFFF', EndColorStr='#FFAAAA')
          }

          .error {
          background-color: #FFFFAA; /* yellow */
          filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#FFFFFF', EndColorStr='#FFFFAA')
          }

          .input {
          background-color: #0033CC; /* blue */
          filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#FFFFFF', EndColorStr='#AAAAFF')
          }

          .output-only {
          background-color: #808080; /* grey */
          filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#FFFFFF', EndColorStr='#C0C0C0')
          }

          .valueType { font-size: 80%; font: italic; 	color: #663333; }

          .missingInput { color: red; margin-right: 3px; margin-left: 3px; }

          .missingOutput { color: red; margin-right: 3px; margin-left: 3px; }

          body
          {
          margin: 0px;
          padding: 0px;
          font-family: trebuchet ms, verdana, tahoma, arial, sans-serif;
          /*font-size: 0.7em;*/
          background-color: white;
          }

          table
          {
          background: #EEEEEE;
          margin: 2px;
          padding: 0px;
          border: solid #AAAAAA;
          border-width: 1px 0px 0px 1px;
          font-size: 0.9em;
          }

          td, th
          {
          border: solid #AAAAAA;
          border-width: 0px 1px 1px 0px;
          padding: 1px 3px 1px 3px;
          }

        </style>
      </head>
      <body>
        <h1>Test Results</h1>

        <!--list out the function table of contents-->
        <ul>
          <xsl:for-each select ="/Files/File">
            <xsl:variable name="file" select="document(.)/TestClassResults" />
            <li>
              <xsl:value-of select="$file"/>
              <xsl:variable name="class" select="$file/@Name" />
              <a>
                <xsl:attribute name="href">
                  #<xsl:value-of select="$class"/>
                </xsl:attribute>
                <xsl:value-of select="$class"/>
              </a>
              <ul>
                <xsl:for-each select ="$file/TestMethodsSummary/TestMethodSummary">
                  <li>
                    <a>
                      <xsl:attribute name="href">
                        #<xsl:value-of select="$class"/>.<xsl:value-of select="@Name"/>
                      </xsl:attribute>
                      <xsl:value-of select="@Name"/>
                    </a>
                    <xsl:if test="count(InputsSummary/InputSummary[@Missing='True']) > 0">
                      - Missing inputs:
                      <xsl:for-each select="InputsSummary/InputSummary[@Missing='True']">
                        <span class='missingInput'>
                          <xsl:value-of select="@Name"/>
                        </span>
                      </xsl:for-each>
                    </xsl:if>
                    <xsl:if test="count(InputsSummary/InputSummary[@Missing='True']) > 0">
                      - Missing outputs:
                      <xsl:for-each select="AssertsSummary/AssertSummary[@Missing='True']">
                        <span class='missingOutput'>
                          <xsl:value-of select="@Name"/>
                        </span>
                      </xsl:for-each>
                    </xsl:if>
                  </li>
                </xsl:for-each>
              </ul>
            </li>
          </xsl:for-each>
        </ul>

        <xsl:for-each select ="/Files/File">
          <xsl:for-each select="document(.)/TestClassResults">
            <xsl:variable name="class" select ="@Name" />
            <h2>
              <a>
                <xsl:attribute name="name">
                  <xsl:value-of select="$class"/>
                </xsl:attribute>
                <xsl:value-of select="$class"/>
              </a>
            </h2>

            <xsl:for-each select="TestMethodsSummary/TestMethodSummary">
              <xsl:variable name="method" select="@Name" />
              <h3>
                <a>
                  <xsl:attribute name="name">
                    <xsl:value-of select="$class"/>.<xsl:value-of select="$method"/>
                  </xsl:attribute>
                  <xsl:value-of select="$method"/>
                </a>
              </h3>

              <table border="1" cellspacing="0">
                <tr>
                  <th>
                    Row
                  </th>
                  <xsl:for-each select="InputsSummary/InputSummary[@Missing='False']">
                    <th>
                      <xsl:value-of select="@Name"/>
                    </th>
                  </xsl:for-each>
                  <xsl:for-each select="AssertsSummary/AssertSummary[@Missing='False']">
                    <th>
                      <xsl:value-of select="@Name"/>
                    </th>
                  </xsl:for-each>
                </tr>
                <xsl:for-each select ="../../TestMethods/TestMethod[@Name=$method]" >
                  <tr>
                    <td>
                      <xsl:value-of select="position()"/>
                    </td>
                    <xsl:for-each select="Inputs/Input[@Missing='False']">
                      <td class="input">
                        <xsl:value-of select="@Value"/>
                      </td>
                    </xsl:for-each>
                    <xsl:for-each select="Inputs/Input[@Missing='False']">
                      <xsl:choose>
                        <xsl:when test="contains('@Name', '??')">
                          <td class="output">
                            <xsl:value-of select="@Value"/>
                          </td>
                        </xsl:when>
                      </xsl:choose>
                    </xsl:for-each>
                    <xsl:for-each select="Asserts/Assert[@Missing='False']">
                      <xsl:choose>
                        <xsl:when test="contains(@Name, '??') = 'True'" >
                          <td class="output-only">
                            <xsl:value-of select="@Actual"/>
                          </td>
                        </xsl:when>
                        <xsl:when test="@TestPassed = 'True'" >
                          <td class="pass">
                            <xsl:value-of select="@Actual"/>
                          </td>
                        </xsl:when>
                        <xsl:when test="string-length(ErrorException/@Full) &gt; 0">
                          <td class="error">
                            <pre>
                              <xsl:value-of select="ErrorException/@Full"/>
                            </pre>
                          </td>
                        </xsl:when>
                        <xsl:otherwise >
                          <td class="fail">
                            <xsl:value-of select="@Expected"/>
                            <span class='valueType'> expected</span>
                            <hr/>
                            <xsl:value-of select="@Actual"/>
                            <span class='valueType'> actual</span>
                          </td>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:for-each>
                  </tr>
                </xsl:for-each >
              </table>
            </xsl:for-each>
          </xsl:for-each>
        </xsl:for-each>

      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>
